<template>
  <view class="patrolInspect-detail">
    <view class="universal-detail-cont">
      <view class="universal-detail-item">
        <view class="universal-detail-item-title">所属工程：</view>
        <view class="universal-detail-item-cont">{{ detail.projectItemName }}</view>
      </view>
      <view class="universal-detail-item">
        <view class="universal-detail-item-title">关联设备：</view>
        <view class="universal-detail-item-cont">{{ detail.objectName }}</view>
      </view>
      <view class="universal-detail-item">
        <view class="universal-detail-item-title">巡查要点描述：</view>
        <view class="universal-detail-item-cont">{{ detail.attentionRemark }}</view>
      </view>
      <view class="universal-detail-item">
        <view class="universal-detail-item-title">检查结果：</view>
        <van-radio-group v-model="form.dangerFlag" direction="horizontal">
          <van-radio :name="0">正常</van-radio>
          <van-radio :name="1">隐患</van-radio>
        </van-radio-group>
      </view>

      <form-troble ref="formTrobleRef" :detail="detail" v-if="form.dangerFlag === 1" @confirm="onConfirm"></form-troble>
      <form-patrol ref="formPatrolRef" :detail="detail" v-if="form.dangerFlag === 0" @confirm="onConfirm"></form-patrol>
    </view>
  </view>
</template>

<script setup>
import formPatrol from './form-patrol';
import formTroble from './form-troble';

import { ref, onMounted } from 'vue';
import { apiPatrolTaskItemSumbit } from '@/api/patrolInspect';

const emit = defineEmits(['getDetail']);
const props = defineProps({
  detail: Object
});
const form = ref({
  dangerFlag: 0,
})
const formTrobleRef = ref(null);
const formPatrolRef = ref(null);
// 提交巡查点
const onConfirm = (params) => {
  apiPatrolTaskItemSumbit({
    ...params,
    ...form.value,
    lineItemId: props.detail.lineItemId,
    lineTaskId: props.detail.lineTaskId,
  }).then(res => {
    form.value.dangerFlag === 0 ? formPatrolRef.value.initLoading() : formTrobleRef.value.initLoading();
    emit('getDetail');
  })
}

</script>

<style lang="scss" scoped>
@import '@/assets/universal-detail.scss';
@import '@/assets/patrolInspect.scss';
</style>